package com.bases {
	import com.skin.SkinManage;
	import com.utils.SCUiTool;
	import flash.display.Bitmap;
	import flash.filters.DropShadowFilter;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import org.bytearray.display.ScaleBitmap;

	public class WindowBg extends TUIComponent {
		private var _bg_bmp:ScaleBitmap;
		private var _title_bg_bmp:Bitmap;
		private var _title_tf:TLable;
		private var _w:uint = 270;
		private var _h:uint = 156;

		public function WindowBg(title:String = '窗口', w:uint = 270, h:uint = 156){
			this.mouseChildren = false;
			this._w = w > this._w ? w : this._w;
			this._h = h > this._h ? h : this._h;
			this.addSkin();
			this._bg_bmp.scale9Grid = new Rectangle(144, 102, 6, 7);
//			this._title_tf=SCUiTool.buildWindowTitleTextField();
			this._title_tf = new TLable();
			this._title_tf.text = title;
			this.addChild(_bg_bmp);
			//this.addChild(_title_bg_bmp);
			this.addChild(_title_tf);
			this.relayout();
		}

		override protected function relayout():void {
//			this.width=_w;
//			this.height=_h;
			this._bg_bmp.setSize(_w, _h - 6);
			//this._title_bg_bmp.x=_w/2-this._title_bg_bmp.width/2;
			//this._title_bg_bmp.y=-6;
			this._title_tf.x = 5; //_w/2-this._title_tf.width/2;
			this._title_tf.y = 5;
			this._title_tf.width = this._title_tf.textWidth + 18;
			this._title_tf.setFontSize(13, 0x222222);
			this._bg_bmp.filters = [new DropShadowFilter(4, 45, 0, .8, 8, 8)];
		}

		public function set title(txt:String):void {
			this._title_tf.text = txt;
			this._title_tf.x = 10;
			this._title_tf.y = 10;
			this._title_tf.setFontSize(14, 0xfded01);
		}

		override public function setSize(w:Number, h:Number):void {
			_w = w;
			_h = h;
			this.relayout();
		}

		private function addSkin():void {
			this._bg_bmp = new ScaleBitmap(SkinManage.getInstance().getBitmapData('AlertBg'));
			//this._title_bg_bmp=new Bitmap(new WindowTitleBg(0,0));
		}
	}
}